home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 10 - 1994 / 10.05 May 94 / SerialEx / Project Data < prev    next >
Encoding:
Text File  |  1994-03-20  |  2.6 KB  |  82 lines  |  [TEXT/ttxt]

  1. // © Copyright 1994 Apple Computer, Inc, All Rights Reserved
  2.  
  3. // Basic constants that we may or may not need
  4. constant kAppName     := '|SerialEx:PIEDTS|;
  5. constant kAppSymbol    := '|SerialEx:PIEDTS|;
  6.  
  7.  
  8. // This is our protoEndpoint specification. Note we are
  9. // using DefConst so the symbol is known as a constant when
  10. // we compile the proto, and later use it during runtime.
  11.  
  12. DefConst('protoLlamaPEndpoint, {
  13. // basic endpoint proto
  14.     _proto: protoEndpoint,
  15.  
  16. // Options (array stored inside the configOptions slot.
  17.     configOptions: [
  18.         // basic serial port
  19.         { label: kCMSAsyncSerial, type: 'service, opCode: opSetRequired },
  20.         // basic serial port options
  21.       { label: kCMOSerialIOParms, type: 'option, opCode: opSetNegotiate,
  22.         data: { bps: k9600bps, dataBits: k8DataBits, stopBits: k1StopBits, 
  23.           parity: kNoParity } },
  24.         // flow control (XON/XOFF)
  25.       { label: kCMOInputFlowControlParms, type: 'option, opCode: opSetNegotiate,
  26.         data: { xonChar: unicodeDC1, xoffChar: unicodeDC3, useSoftFlowControl: true, 
  27.         useHardFlowControl: nil } },
  28.    ],
  29.  
  30. //    Our exception handler (asynch exceptions from the endpoint).
  31.     exceptionHandler: func(exception)
  32.     begin
  33.         print("Got the exception from Abort, ignoring it for the time being");
  34.     end,
  35.  
  36. // Our state machines:
  37. // WaitForAck, main dispatcher, waits for the first ACK from the other side.
  38.    waitForACK:
  39.    {
  40.         InputForm: 'string,
  41.         endCharacter: $?,             // ACK? expected
  42.        discardAfter: 200,            // scan buffer size
  43.        
  44.         InputScript: func(endpoint, s)
  45.        begin
  46.            if (StrPos(s, "ACK?", 0)) then    // send response (help instructions in this case)
  47.           begin
  48.              endpoint:Output("Send any of the following commands:" & unicodeCR &
  49.                                         unicodeLF, nil);  
  50.                 endpoint:Output("PLAY! -- will play a tone on the Newton" & unicodeCR &
  51.                                         unicodeLF, nil);
  52.                 endpoint:Output("Add more comments if more functions...." & unicodeCR &
  53.                                         unicodeLF, nil);
  54.              endpoint:FlushOutput();
  55.              endpoint:SetInputSpec(endpoint.waitForFUNCTION); // the main dispatch loop
  56.              end
  57.    end,
  58.    },
  59.  
  60.  
  61.     // This is the generic dispatcher state, send something ending with ! and
  62.    // the Newton will serve.
  63.     waitForFUNCTION:
  64.     {
  65.         InputForm: 'string,
  66.       endCharacter: $!,          // expects a '!' as part of the command
  67.        discardAfter: 200,            // scan buffer size
  68.  
  69.       InputScript: func(endpoint, s)
  70.       begin
  71.               if(StrPos(s, "PLAY!", 0)) then      // play function
  72.             begin
  73.                 PlaySound(ROM_funbeep);
  74.                endpoint:Output(unicodeCR, nil);
  75.                endpoint:Output(unicodeLF, nil);
  76.                endpoint:FlushOutput();
  77.             end;
  78.        end;
  79.     }, 
  80. });
  81.  
  82.